//
//  YBBaseItem.m
//  YanzhouCloud
//
//  Created by Cocoa on 2019/7/1.
//  Copyright © 2019 yibai. All rights reserved.
//

#import "YBBaseItem.h"
#import <objc/runtime.h>

@implementation YBBaseItem

+ (NSDictionary *)mj_replacedKeyFromPropertyName {
    return @{@"ID": @"id"};
}

- (NSString *)description
{
    Class clazz = [self class];
    u_int count;
    
    objc_property_t* properties = class_copyPropertyList(clazz, &count);
    NSMutableArray* propertyArray = [NSMutableArray arrayWithCapacity:count];
    
    for (int i = 0; i < count ; i++)
    {
        const char* propertyName = property_getName(properties[i]);
        
        [propertyArray addObject:[NSString  stringWithCString:propertyName encoding:NSUTF8StringEncoding]];
    }
    
    free(properties);
    
    NSMutableString *str = [[NSMutableString alloc] init];
    for (NSString *name in propertyArray)
    {
        
        id value = [self valueForKey:name];
        
        [str appendFormat:@"key: %@  value : %@ \n", name,value ];
    }
    return str;
}

- (id)copyWithZone:(NSZone *)zone
{
    id objCopy = [[[self class] allocWithZone:zone] init];
    Class clazz = [self class];
    u_int count;
    objc_property_t* properties = class_copyPropertyList(clazz, &count);
    NSMutableArray* propertyArray = [NSMutableArray arrayWithCapacity:count];
    
    for (int i = 0; i < count ; i++)
    {
        const char* propertyName = property_getName(properties[i]);
        [propertyArray addObject:[NSString  stringWithCString:propertyName encoding:NSUTF8StringEncoding]];
    }
    
    free(properties);
    for (int i = 0; i < count ; i++)
    {
        NSString *name=[propertyArray objectAtIndex:i];
        id value=[self valueForKey:name];
        if([value respondsToSelector:@selector(copyWithZone:)])
        {[objCopy setValue:[value copy] forKey:name];}
        else
        {[objCopy setValue:value  forKey:name];}
    }
    return objCopy;
}
- (NSString *)cellID {
    return @"";
}
@end
